package com.yunhai.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.device.service.DeviceCategoryService;
import com.yunhai.model.entity.dms.DmsDeviceCategoryEntity;
import com.yunhai.model.vo.dms.DmsDeviceCategoryQuery;
import com.yunhai.model.vo.dms.DmsDeviceCategoryVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/deviceCategory")
public class DeviceCategoryController {

	@Resource
	private DeviceCategoryService deviceCategoryService;


	/**
	 * 获取 DeviceCategory 分页列表
	 */
	@GetMapping("/pagination")
	public Ret getDeviceCategoryPagination(PaginationVo paginationVo, DmsDeviceCategoryQuery dmsDeviceCategoryQuery ) throws Exception {
		IPage page = deviceCategoryService.getDeviceCategoryPagination(paginationVo, dmsDeviceCategoryQuery );
		return Ret.toPage(page);
	}


	/**
	 * 获取 DeviceCategory 所有数据
	 */
	@GetMapping("/allList")
	public Ret getDeviceCategoryAllList( DmsDeviceCategoryQuery dmsDeviceCategoryQuery ) throws Exception {
		List<DmsDeviceCategoryEntity> list = deviceCategoryService.getDeviceCategoryAllList( dmsDeviceCategoryQuery );
		return Ret.ok(list);
	}


	/**
	 * 获取 DeviceCategory 详情
	 */
	@GetMapping("/{id}")
	public Ret getDeviceCategoryDetailById(@PathVariable Long id) throws Exception {

	    DmsDeviceCategoryEntity dmsDeviceCategoryEntity = deviceCategoryService.getDeviceCategoryDetail(id);
		return Ret.ok(dmsDeviceCategoryEntity);
	}


	/**
	 * 新增 DeviceCategory
	 * */
	@PostMapping("")
	public Ret addDeviceCategory(@RequestBody DmsDeviceCategoryVo dmsDeviceCategoryVo) throws Exception {

		deviceCategoryService.addDeviceCategory(dmsDeviceCategoryVo);
		return Ret.ok();
	}


	/**
	 * 更新 DeviceCategory
	 * */
	@PutMapping("")
	public Ret updateDeviceCategory(@RequestBody DmsDeviceCategoryVo dmsDeviceCategoryVo) throws Exception {

		deviceCategoryService.updateDeviceCategory(dmsDeviceCategoryVo);
		return Ret.ok();
	}


	/**
	 * 删除 DeviceCategory
	 * */
	@PostMapping("/batchRemove")
	public Ret batchRemoveDeviceCategory( @RequestBody List<Long> ids ) throws Exception {

	    deviceCategoryService.batchRemoveDeviceCategory(ids);
		return Ret.ok();
	}
}
